<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">材料进出库记录（反向操作记录编辑或删除，可能导致数据错误，请谨慎操作！）</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        {{# if(d.type != 'ru'){ }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_edit({{d.id}},'{{d.type}}')">编辑</a>
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_delete({{d.id}},'{{d.type}}')">删除</a>
        {{# } }}
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>

<script type="text/javascript">
    var parent_ruid = getQueryVariable('ruid') || 0;

    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;
        $("#search_table").hide();
        setSouTableExport('入库记录');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_stuff_mingxi_detail),where: {ruid:parent_ruid}, page: false
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);


                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'number', title: '单号'}
                ,{field: 'dt', title: '日期'}
                ,{field: 'dongname', title: '动作'}
                ,{field: 'name', title: '物资名称及规格'}
                ,{field: 'unit', title: '单位'}
                ,{field: 'price', title: '单价(元)'}
                ,{field: 'num', title: '数量'}
                ,{field: 'money', title: '金额(元)'}
                ,{field: 'baner', title: '经手人'}
                ,{field: 'gonger', title: '供应商'}
                ,{field: 'enginname', title: '项目名称'}
                ,{field: 'caiid_name', title: '合同名称'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });



    function auth_but_func_edit(id, type){
        if(type == 'chu'){
            openPageEdit('chu_edit.php?id='+id);
        }
        if(type == 'tui'){
            openPageEdit('tui_edit.php?id='+id);
        }
    }
    function auth_but_func_delete(id, type){
        if(type == 'chu'){
            data_delete(ask_stuff_chu_del, {id:id});
        }
        if(type == 'tui'){
            data_delete(ask_stuff_tui_del, {id:id});
        }
    }







    function layer_close(){
        try {
            parent.layui.table.reload('datalist');
        }catch (e) {

        }
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

</script>
</body>
</html>
